<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="6" :md="6" :sm="24">
            <a-form-item label="商品编号">
              <a-input placeholder="请输入商品编号" v-model="queryParam.code" style="width: 100%"></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl="7" :lg="7" :md="7" :sm="24">
            <a-form-item label="供应商商品编号">
              <a-input placeholder="请输入供应商商品编号" v-model="queryParam.gysCode" style="width: 100%"></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="6" :md="6" :sm="24">
            <a-form-item label="销售状态">
              <a-select placeholder="请选择销售状态" style="width: 100%" v-model="queryParam.status">
                <a-select-option value="0">
                  上架中
                </a-select-option>
                <a-select-option value="2">
                  已下架
                </a-select-option>
              </a-select>
            </a-form-item>

          </a-col>

        </a-row>

        <a-row :gutter="24">
          <a-col :xl="3" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
                <a-button type="primary" @click="showModal" style="margin-left: 8px">添加主推商品</a-button>
            </span>
          </a-col>
        </a-row>

        <!--新增主推面料弹框-->
        <a-modal
          title="新增主推商品"
          v-model:visible="visible2"
          :confirm-loading="confirmLoading"
          @ok="addFirst"
          @close="cleatDate"
        >
          <a-form>
            <a-form-item label="商品编号">
              <a-input v-model="code" placeholder="请输入商品编号"></a-input>
            </a-form-item>
            <a-form-item label="商品价格">
              <a-input-number style="width: 100%" v-model="price" placeholder="商品价格" suffix="元"></a-input-number>
            </a-form-item>
            <a-form-item label="备注">
              <a-textarea v-model="remark" placeholder="备注" :rows="4"></a-textarea>
            </a-form-item>
          </a-form>
        </a-modal>
        <!--新增主推面料弹框结束-->
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!--table区域-begin-->
    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>

        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="30px" alt=""
               style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a-menu-item style="display: inline;margin-left: 10px">
<!--            <a @click="showDrawer(record),getFabricDetail(record.id)">查看详情</a>-->
            <a @click="gotoGoodsDetail(record.id)">查看详情</a>
          </a-menu-item>
          <a-menu-item style="display: inline;margin-left: 10px">
<!--            <a @click="gotoUpdate(record.id)">编辑</a>-->
            <a @click="gotoUpdate(record.id)">编辑</a>
          </a-menu-item>
          <a-menu-item style="display: inline;margin-left: 10px">
                  <a-popconfirm title="确定删除吗?" @confirm="() => fabricDel(record.id)">
                    <a style="color:deepskyblue">删除</a>
                  </a-popconfirm>
          </a-menu-item>
          <a-menu-item v-if="record.status=='0'" style="display: inline;margin-left: 10px">
                  <a-popconfirm title="确定下架吗?" @confirm="() => FabricSer(record.id)">
                    <a style="color:deepskyblue">下架</a>
                  </a-popconfirm>
          </a-menu-item>

          <a-menu-item v-if="record.status=='2'" style="display: inline;margin-left: 10px">
                  <a-popconfirm title="确定上架吗?" @confirm="() => fabricIDFunc(record.id)">
                    <a style="color:deepskyblue">上架</a>
                  </a-popconfirm>
          </a-menu-item>
        </span>
      </a-table>
    </div>

    <!--详情的弹框-->
    <!--    <div>
          <a-drawer
            title="面料基本信息"
            placement="right"
            :closable="false"
            :visible="visible"
            :after-visible-change="afterVisibleChange"
            :width="648"
            @close="onClose"
          >
            &lt;!&ndash;上方的订单基础信息&ndash;&gt;
            <div style="margin-top: 10px;width: 100%;margin-bottom: 30px;">
              <table>
                <tr class="mytr">
                  <td class="fatitle">面料编号</td>
                  <td class="facontent">{{ fabricDetail.fabricCode }}</td>
                  <td class="fatitle">面料类型</td>
                  <td v-if="fabricDetail.fabricTypeId==1" class="facontent">素色</td>
                  <td v-if="fabricDetail.fabricTypeId==2" class="facontent">条纹</td>
                  <td v-if="fabricDetail.fabricTypeId==3" class="facontent">格子</td>
                </tr>
                <tr class="mytr">
                  <td class="fatitle">供应商面料编号</td>
                  <td class="facontent">{{ fabricDetail.gysfabriccode }}</td>
                  <td class="fatitle">供应商</td>
                  <td class="facontent">{{ fabricDetail.gysname }}</td>
                </tr>
                <tr class="mytr">
                  <td class="fatitle">是否进口</td>
                  <td class="facontent">{{ fabricDetail.isimport == '0' ? '国产' : '进口' }}</td>
                  <td class="fatitle">面料产地</td>
                  <td class="facontent">{{ fabricDetail.fabricSource }}</td>
                </tr>
                <tr class="mytr">
                  <td class="fatitle">面料品牌</td>
                  <td class="facontent">{{ fabricDetail.pingpai }}</td>
                  <td class="fatitle">面料成分</td>
                  <td class="facontent">{{ fabricDetail.fabricContent }}</td>
                </tr>

                <tr class="mytr">
                  <td class="fatitle">面料纱织</td>
                  <td class="facontent">{{ fabricDetail.fabricShazhi }}</td>
                  <td class="fatitle">面料克重</td>
                  <td class="facontent">{{ fabricDetail.fabricWeight }}</td>
                </tr>

                <tr class="mytr">
                  <td class="fatitle">面料门幅</td>
                  <td class="facontent">{{ fabricDetail.menfu }}</td>
                  <td class="fatitle">面料颜色</td>
                  <td class="facontent">{{ fabricDetail.fabriceColor }}</td>
                </tr>

                <tr class="mytr">
                  <td class="fatitle">面料花型</td>
                  <td class="facontent">{{ fabricDetail.hua }}</td>
                  <td class="fatitle">面料季节</td>
                  <td class="facontent">{{ fabricDetail.season }}</td>
                </tr>

                <tr class="mytr">
                  <td class="fatitle">库存</td>
                  <td class="facontent">{{ fabricDetail.inventory }}</td>
                  <td class="fatitle">排序</td>
                  <td class="facontent">{{ fabricDetail.paixu }}</td>
                </tr>
              </table>
            </div>

            &lt;!&ndash;弹框要显示的内容,遍历面料&ndash;&gt;
            <div style="left: 10px;margin-bottom: 20px;">

              <div style="margin-left: 10px">
                &lt;!&ndash;左边的图片&ndash;&gt;
                <div style="float: left">
                  <img style="width: 153px;height: 158px;left: 10px;margin-top: 10px" :src="fabricDetail.fabricImg">
                  </img>
                </div>

                <div>
                  <table style="width: 100%">

                  </table>
                </div>
              </div>
            </div>
            <div>面料备注信息：</div>
            <span>{{ fabricDetail.remark }}</span>
          </a-drawer>
        </div>-->
    <!--弹框结束-->
  </a-card>

</template>

<script>
import '@/assets/less/TableExpand.less'
import {mixinDevice} from '@/utils/mixin'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import JDate from '@/components/jeecg/JDate.vue'
import {getAction} from "../../api/manage";

export default {
  name: 'FirstFabric',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    JDate
    // LgyxCreditRateModal
  },
  data() {
    return {
      visible: false, // 右侧详情弹框的显示
      visible2: false, // 新增弹框的显示
      description: '面料订单',
      fabricDetail: {}, // 面料详情,
      code: '',//商品编码
      price: '',// 价格
      remark: '', // 备注
      /*fabricOrderDetail: [], // 当前的面料订单详情
      orderDetail: {}, // 订单详情*/
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '商品编号',
          align: "center",
          dataIndex: 'goodsCode'
        },
        {
          title: '供应商商品编号',
          align: "center",
          dataIndex: 'supplierGoodsCode'
          /* customRender: (text) => {
             //字典值替换通用方法
             return filterDictTextByCache('sex', text);
           }*/
        },
        {
          title: '缩略图',
          align: "center",
          dataIndex: 'goodsMainImg',
          scopedSlots: {customRender: 'imgSlot'}
        },
        {
          title: '零售价',
          align: "center",
          dataIndex: 'price'
        },
        /*{
          title: '库存（米）',
          align: "center",
          dataIndex: 'inventory'
        },*/
        /*{
          title: '品牌',
          align: "center",
          dataIndex: 'pingpai'
        },*/
        /*{
          title: '面料组',
          align: "center",
          dataIndex: 'groupName'
        },*/
        {
          title: '销售状态',
          align: "center",
          dataIndex: 'status',
          customRender: function (text) {
            if (text == '0') {
              return '上架中'
            } else if (text == '2') {
              return '已下架'
            }
          }
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          // fixed:"right",
          width: 147,
          scopedSlots: {customRender: 'action'}
        }
      ],
      url: {
        list: '/goodsCenter/getFirstGoodsList',// 主推商品列表
        addFirstFabric: '/goodsCenter/addFirstGoods', //添加主推商品
        offGoods: '/goodsCenter/offGoods', // 下架商品
        upGoods: '/goodsCenter/upGoods', // 上架商品
        delGoods: '/goodsCenter/delGoods', // 删除商品

        delFabric: '/fabricCenter/delFabric',//删除面料
        serFabric: '/fabricCenter/serFabric', //下架面料
        fanricDetail: '/fabricCenter/getFabricDetail', //面料详情
        fabricUp: '/fabricCenter/fabricUp', //上架面料
      },
      dictOptions: {},
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {

    /**
     * 前往商品详情界面  /goodsCenter/GoodsDetail
     */
    gotoGoodsDetail(id) {
      this.$router.push({path: '/goodsCenter/GoodsDetail', query: {id: id, group: this.$route.query.group}})
    },

    /**
     * 面料上架
     */
    fabricIDFunc(fabricID) {
      getAction(this.url.upGoods, {
        'id': fabricID
      }).then(res => {
        if (res.code == '200') {
          this.$message.success("上架成功")
          this.loadData()
        } else {
          this.$message.error("上架失败")
        }
      })
    },
    addFirst() { // 添加主推面料
      getAction(this.url.addFirstFabric, {
        'code': this.code,
        'price': this.price,
        'remark': this.remark
      }).then(res => {
        this.visible2 = false
        this.$message.warning(res.message)
        this.loadData()
      })
    },
    gotoUpdate(id) { // 前往编辑面料界面
      this.$router.push({
        path: '/goodsCenter/UpdateGoods',
        query: {
          id: id,
          group: this.$route.query.group
        }
      })
    },
    showModal() { // 新增主推面料弹框现实
      // this.cleatDate()
      this.visible2 = true;
    },
    // 获取面料详情
    getFabricDetail(id) {
      getAction(this.url.fanricDetail,
        {'fabricID': id}
      ).then(res => {
        this.fabricDetail = res.result
      })
    },
    // 下面三个是详情弹框的方法
    afterVisibleChange(val) {
      console.log('visible', val);
    },
    showDrawer(record) {
      this.orderSn = record.orderSn
      this.orderDetail = record // 订单详情
      this.visible = true;
    },
    onClose() {
      this.visible = false;
      this.fabricOrderDetail = []
    },

    gotoFabricList(groupID) { // 页面跳转
      this.$router.push({
        path: '/fabric/fabricList',
        query: {
          group: groupID
        }
      })
    },

    fabricDel(fabricID) { // 面料删除
      getAction(this.url.delGoods,
        {
          'id': fabricID
        }).then(res => {
        this.cleatDate()
        if (res.code == '200') {
          this.$message.success("删除成功")
          this.loadData()
        } else {
          this.$message.error("删除失败")
        }
      })
    },

    FabricSer(fabricID) { // 面料下架
      getAction(this.url.offGoods,
        {
          'id': fabricID
        }).then(res => {
        this.cleatDate()
        if (res.code == '200') {
          this.$message.success("下架成功")
          this.loadData()
        } else {
          this.$message.error("下架失败")
        }
      })
    },
    cleatDate() { // 添加组之后清楚数据
      this.code = ''
      this.price = ''
      this.remark = ''
      this.visible2 = false
    },
    initDictConfig() {
    }
  }
}
</script>

<style scoped>
@import '~@assets/less/common.less';

.fabricName {
  margin-left: 10px;
  margin-top: 10px;
  width: auto;
  display: block !important;
  background: #2d2d2d;
  color: #ffe56d;
  text-align: center;
  border-radius: 3px;
}

.fabigtitle {
  height: 34px;
  width: 200px;
  text-align: left;
}

.fabigcontent {
  height: 34px;
  width: 200px;
  text-align: right;
}

.fatitle {
  height: 34px;
  width: 82px;
  background: rgb(242 242 242);
  text-align: center;
}

.facontent {
  width: 180px;
  overflow: hidden;
  text-align: center;
}
</style>